
import { _decorator, Component, Node, Button, Prefab, instantiate, LabelComponent } from 'cc';
import { Electron } from './Electron';
const { ccclass, property } = _decorator;
 
@ccclass('Nircmd')
export class Nircmd extends Component {

    @property({
        type: Node, 
        displayName: "所有按钮的父节点", 
        tooltip: "所有nircmd指令按钮的父节点，这个父节点上有layout组件"
    })
    all_btn: Node = null!;

    @property({type: Prefab, displayName: "普通的按钮预制体", tooltip: "普通的按钮预制体"})
    btn: Prefab = null!;

    // 每个按钮的指令，其实前面还有nircmd.exe 
    order: string[] = [
        "setsysvolume 65535",
        "mutesysvolume 1",
        "mutesysvolume 0",
        "standby",
        `qboxcom "你想重新启动你的计算机吗?" "重启" exitwin reboot`,
        "clipboard set ~$folder.desktop$",
        "clipboard clear",
        `cmdwait 2000 savescreenshot ~$folder.desktop$/延迟2秒截屏到桌面.png`,
        "savescreenshot ~$folder.desktop$/截图到桌面.png",
        "beep 500 2000",
        "stdbeep",
        `nircmd infobox "你点击了弹窗" "一个可爱的弹窗"`,
    ];

    // 每个指令的名字，这个将显示到按钮的文字上
    order_name: string[] = [
        "设置为最高音量",
        "设置为静音",
        "取消静音",
        "进入待机状态",
        "弹窗重启",
        "复制桌面路径",
        "清空剪切板",
        "延迟两秒截图到桌面",
        "截图到桌面",
        "发出嘟嘟声",
        "标准嘟嘟声",
        "弹窗",
    ];

    onLoad () {
        // 生成按钮
        for (let i = 0; i < this.order.length; i++) {
            // 生成
            let node = instantiate(this.btn);
            node.parent = this.all_btn;
            
            // 设置名称
            node.children[0].getComponent(LabelComponent)!.string = this.order_name[i];

            // 结束触摸时执行指令
            node.on(Node.EventType.TOUCH_END, () => {
                Electron.nircmdUD(this.order[i]);
            });
        }
    }

}